package cn.practice.chat.lang;

import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @ClassName Result
 * @Description:
 * @Author A-TAO
 * @Date 2022/10/30
 * @Version V1.0
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {

    private static final long serialVersionUID = -1122384555865271510L;


    private int code;

    private String msg;

    private T data;

    private Integer currentPage;
    private Integer pageSize;

    private long total;


    public static  Result success(){
        Result r = new Result();
        r.setCode(HttpStatus.HTTP_OK);
        r.setMsg("success");
        return r;
    }


    public static <T> Result<T> success(T data){
        return success(HttpStatus.HTTP_OK,"操作成功", data);
    }

    public static <T> Result<T> success(int code,String msg, T data){
        Result r = new Result();
        r.setData(data);
        r.setMsg(msg);
        r.setCode(code);
        return r;
    }

    public static Result error(){
        return baseError(HttpStatus.HTTP_INTERNAL_ERROR, "FAIL");
    }


    public static Result error(String msg){
        return baseError(HttpStatus.HTTP_INTERNAL_ERROR, msg);
    }


    public static  Result error(int code, String msg){
        return  baseError(code, msg);
    }

    private  static Result baseError(int code,String msg){
        Result r = new Result();
        r.setMsg(msg);
        r.setCode(code);
        return r;
    }
}
